#!/usr/bin/python3
# -*- coding:utf-8 -*-
# __author__ == taoyulong2018@gmail.com
# __time__ == 2023/11/30 19:15
# ===========================================
#       题目名称： 66. 加一
#       题目地址： https://leetcode.cn/problems/plus-one/
#       题目描述： https://note.youdao.com/s/VjIUrvCD
# ===========================================
from typing import *


class Solution:

    def plusOne(self, digits: List[int]) -> List[int]:
        is_carry = False
        res = []
        digits = digits.copy()
        while digits:
            cur_digit = digits.pop()  # 当前值
            if not res or is_carry:
                cur_digit += 1
                if cur_digit > 9:
                    is_carry = True
                    res.insert(0, cur_digit - 10)
                    continue
            res.insert(0, cur_digit)
            is_carry = False
        else:
            if is_carry:
                res.insert(0, 1)
        return res


if __name__ == '__main__':
    s = Solution()
    items = [
        {"req_params": [1, 2, 3], "final_result": [1, 2, 4]},
        {"req_params": [4, 3, 2, 1], "final_result": [4, 3, 2, 2]},
        {"req_params": [0], "final_result": [1]},
        {"req_params": [9], "final_result": [1, 0]},
        {"req_params": [8, 9, 9, 9], "final_result": [9, 0, 0, 0]},
    ]
    for item in items:
        print("%s + 1 预期结果为: %s, 实际结果为：%s" % (item["req_params"], item["final_result"], s.plusOne(item["req_params"])))
